package com.codi.api.controller.fund;

import com.codi.api.security.UserUtil;
import com.codi.base.log.annotation.Loggable;
import com.codi.bus.core.fund.enums.FundDividendChangeBizTypeEnum;
import com.codi.bus.core.fund.request.DividendChangeRequestDto;
import com.codi.bus.core.fund.request.MyDividendHistoryRequestDto;
import com.codi.bus.core.fund.service.FundDividendService;
import com.codi.bus.core.resultModel.BaseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 模块名
 *
 * @author spy
 * @version 1.0 2018-01-25
 * @since 1.0
 */
@Slf4j
@RestController
@RequestMapping("fund/dividend")
public class DividendController {

    @Autowired
    private FundDividendService fundDividendService;

    @Loggable
    @GetMapping("/my")
    public BaseResult queryDividend(@Validated MyDividendHistoryRequestDto dto) {
        Long userId = UserUtil.getLoginUserId();
        dto.setUserId(userId);

        return fundDividendService.queryMyDividendHistory(dto);
    }

    @Loggable
    @PostMapping("/change")
    public BaseResult changeDefaultMethod(@Validated DividendChangeRequestDto dto) {
        Long userId = UserUtil.getLoginUserId();
        dto.setUserId(userId);
        dto.setBizType(FundDividendChangeBizTypeEnum.COMMON.getKey());

        return fundDividendService.change(dto);
    }


}
